// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   IVL_MOImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_MO;
import com.sunwayhorizo.health.hl7.datatypes.IVL_REAL;
import com.sunwayhorizo.health.hl7.datatypes.MO;
import com.sunwayhorizo.health.hl7.datatypes.QTY;
import com.sunwayhorizo.health.hl7.datatypes.REAL;
import com.sunwayhorizo.health.hl7.datatypes.SET_MO;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, IVL_REALImpl, 
//            MOImpl, NullFlavorImpl, REALImpl, TYPEImpl

public class IVL_MOImpl extends ANYImpl
    implements IVL_MO
{

    public static final String RCS_ID = "$Header: IVL_MOImpl.java 115.23 2005/09/16 09:22:57 amchanda noship $";
    protected REAL _low;
    protected REAL _high;
    protected BL _lowClosed;
    protected BL _highClosed;
    protected CS _currency;
    protected MO _center;
    protected MO _width;
    protected MO _lowMO;
    protected MO _highMO;
    protected IVL_REAL _value;
    private static final IVL_MO nullNI = new IVL_MOImpl(CSImpl.valueOf("NI"));
    private static final IVL_MO nullOTH = new IVL_MOImpl(CSImpl.valueOf("OTH"));
    private static final IVL_MO nullNINF = new IVL_MOImpl(CSImpl.valueOf("NINF"));
    private static final IVL_MO nullPINF = new IVL_MOImpl(CSImpl.valueOf("PINF"));
    private static final IVL_MO nullUNK = new IVL_MOImpl(CSImpl.valueOf("UNK"));
    private static final IVL_MO nullASKU = new IVL_MOImpl(CSImpl.valueOf("ASKU"));
    private static final IVL_MO nullNAV = new IVL_MOImpl(CSImpl.valueOf("NAV"));
    private static final IVL_MO nullMSK = new IVL_MOImpl(CSImpl.valueOf("MSK"));
    private static final IVL_MO nullNA = new IVL_MOImpl(CSImpl.valueOf("NA"));
    private static final IVL_MO nullNASK = new IVL_MOImpl(CSImpl.valueOf("NASK"));

    public static IVL_MO valueOf(REAL real, BL bl, REAL real1, BL bl1, CS cs)
    {
        return new IVL_MOImpl(real, bl, real1, bl1, cs);
    }

    public static IVL_MO valueOf(MO mo, BL bl, MO mo1, BL bl1)
    {
        return new IVL_MOImpl(mo, bl, mo1, bl1);
    }

    public static IVL_MO nullIVL_MO()
    {
        return new IVL_MOImpl(null);
    }

    private IVL_MOImpl(REAL real, BL bl, REAL real1, BL bl1, CS cs)
    {
        _lowClosed = bl;
        _low = real;
        _high = real1;
        _highClosed = bl1;
        _currency = cs;
    }

    private IVL_MOImpl(MO mo, BL bl, MO mo1, BL bl1)
    {
        if(mo.currency().equal(mo1.currency()).or(mo.isNull().or(mo1.isNull())).isFalse())
        {
            throw ANYImpl.newIntervalException("IVL<MO>", mo.literal().stringValue(), mo1.literal().stringValue());
        } else
        {
            _lowClosed = bl;
            _low = mo.value();
            _high = mo1.value();
            _highClosed = bl1;
            _currency = mo.currency();
            _lowMO = mo;
            _highMO = mo1;
            return;
        }
    }

    private IVL_MOImpl(CS cs)
    {
        super(true, cs);
        _low = REALImpl.nullREAL(NullFlavorImpl.NI);
        _high = REALImpl.nullREAL(NullFlavorImpl.NI);
        _lowClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _highClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _currency = CSImpl.nullCS(NullFlavorImpl.NI);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.IVL_MO;
    }

    public ST literal()
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "literal");
    }

    public MO low()
    {
        if(isNull().isTrue())
            return MOImpl.nullMO();
        if(_lowMO == null)
            _lowMO = MOImpl.valueOf(_low, _currency);
        return _lowMO;
    }

    public MO high()
    {
        if(isNull().isTrue())
            return MOImpl.nullMO();
        if(_highMO == null)
            _highMO = MOImpl.valueOf(_high, _currency);
        return _highMO;
    }

    public BL lowClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _lowClosed;
    }

    public BL highClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _highClosed;
    }

    public QTY width()
    {
        if(isNull().isTrue())
            return MOImpl.nullMO();
        if(_width == null)
            _width = (MO)_highMO.minus(_lowMO);
        return _width;
    }

    public IVL_REAL value()
    {
        if(isNull().isTrue())
            return IVL_REALImpl.nullIVL_REAL();
        if(_value == null)
            _value = IVL_REALImpl.valueOf(_low, _lowClosed, _high, _highClosed);
        return _value;
    }

    public CS currency()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS();
        else
            return _currency;
    }

    public MO center()
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "center");
    }

    public BL contains(MO mo)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return low().lessOrEqual(mo).or(low().isNull()).and(mo.lessOrEqual(high()).or(high().isNull())).and(low().equal(mo).implies(lowClosed())).and(high().equal(mo).implies(highClosed()));
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return width().isZero().and(lowClosed().and(highClosed()).not());
    }

    public BL nonEmpty()
    {
        return isEmpty().not();
    }

    public BL notEmpty()
    {
        return isEmpty().not();
    }

    public BL contains(SET_MO set_mo)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        if(set_mo instanceof IVL_MO)
        {
            IVL_MO ivl_mo = (IVL_MO)set_mo;
            return contains(ivl_mo.low()).and(contains(ivl_mo.high()));
        }
        if(set_mo instanceof SET_MO)
            return contains(((SET_MO) (set_mo.hull())));
        else
            return BLImpl.FALSE;
    }

    public INT cardinality()
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "cardinality");
    }

    public SET_MO union(MO mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "union");
    }

    public SET_MO union(SET_MO set_mo)
    {
        if(set_mo instanceof IVL_MO)
        {
            IVL_MO ivl_mo = (IVL_MO)set_mo;
            if(overlaps(ivl_mo).isTrue())
                return hull(ivl_mo);
        } else
        {
            if(contains(set_mo.hull()).isTrue())
                return this;
            if(set_mo.contains(this).isTrue())
                return set_mo;
        }
        throw ANYImpl.newUnsupportedException("IVL<MO>", "union");
    }

    public SET_MO except(MO mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "except");
    }

    public SET_MO except(SET_MO set_mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "except");
    }

    public SET_MO intersection(SET_MO set_mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "intersection");
    }

    public IVL_MO intersection(IVL_MO ivl_mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "intersection");
    }

    public IVL_MO hull(IVL_MO ivl_mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "hull");
    }

    public IVL_MO Intersection(IVL_MO ivl_mo)
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "Intersection");
    }

    public BL overlaps(IVL_MO ivl_mo)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return contains(ivl_mo.low()).or(contains(ivl_mo.high())).or(ivl_mo.contains(low())).or(ivl_mo.contains(high()));
    }

    public IVL_MO hull()
    {
        return this;
    }

    public IVL_MO nextTo(MO mo)
    {
        if(mo.lessOrEqual(high()).isTrue())
        {
            if(mo.equal(high()).isTrue())
            {
                if(highClosed().isFalse())
                    return this;
                else
                    return nullIVL_MO();
            } else
            {
                return this;
            }
        } else
        {
            return nullIVL_MO();
        }
    }

    public IVL_MO nextAfter(MO mo)
    {
        IVL_MO ivl_mo = nextTo(mo);
        if(ivl_mo.isNull().isFalse() && ivl_mo.contains(mo).isFalse())
            return this;
        else
            return nullIVL_MO();
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof IVL_MO))
            return BLImpl.FALSE;
        IVL_MO ivl_mo = (IVL_MO)any;
        if(isNull().or(any.isNull()).isTrue())
            return BLImpl.FALSE;
        else
            return lowClosed().equal(ivl_mo.lowClosed()).or(lowClosed().isNull().and(ivl_mo.lowClosed().isNull())).and(highClosed().equal(ivl_mo.highClosed()).or(highClosed().isNull().and(ivl_mo.highClosed().isNull()))).and(low().equal(ivl_mo.low()).or(low().isNull().and(ivl_mo.low().isNull()))).and(high().equal(ivl_mo.high()).or(high().isNull().and(ivl_mo.high().isNull())));
    }

    public MO demotion()
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "demotion");
    }

    public Set toSet()
    {
        throw ANYImpl.newUnsupportedException("IVL<MO>", "toSet");
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(low() != null && low().isNull().isFalse())
//                xmlelement.appendChild(((MOImpl)low()).writeXML(xmldocument, "low")[0]);
//            if(high() != null && high().isNull().isFalse())
//                xmlelement.appendChild(((MOImpl)high()).writeXML(xmldocument, "high")[0]);
//            if(width() != null && width().isNull().isFalse())
//                xmlelement.appendChild(((MOImpl)width()).writeXML(xmldocument, "width")[0]);
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static IVL_MO nullIVL_MO(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
